package com.gc.server.controller;

import java.util.HashMap;
import java.util.List;

import com.gc.server.enums.BusApplyLeaveTypeEnum;
import com.gc.server.enums.BusApplyStatusEnum;
import com.gc.server.vo.BusApplyVo;
import com.gc.server.vo.BusApplyVo;
import com.yf.request.SearchParam;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.yf.annotation.SysLog;
import java.util.Map;
import com.yf.consts.DaoConst;
import com.gc.server.entity.BusApplyEntity;
import com.gc.server.service.BusApplyService;
import com.yf.response.R;

import javax.servlet.http.HttpServletResponse;


/**
 * 申请Controller
 *
 * @author hxf
 * @email 505860922@qq.com
 * @date Wed Apr 08 09:33:59 CST 2020
 */
@RestController
@RequestMapping("/bus/apply")
public class BusApplyController {
    @Autowired
    private BusApplyService busApplyService;

    /**
     * 列表申请
     */
    @RequestMapping("/list")
    @RequiresPermissions("bus:apply:list")
    public R list(@RequestBody SearchParam<BusApplyVo> params) {
        PageHelper.startPage(params.getPage(),params.getLimit()).setOrderBy(params.getOrder());
        List<BusApplyVo> busApplyList = busApplyService.queryListVo(params.getEntity());
        return R.ok(new PageInfo(busApplyList));
    }

    /**
     * 查看申请
     */
    @SysLog("查看申请")
    @RequestMapping("/info/{id}")
    @RequiresPermissions("bus:apply:info")
    public R info(@PathVariable("id") Long id) {
        BusApplyEntity busApply = busApplyService.get(id);

        return R.ok(busApply);
    }

    /**
     * 保存申请
     */
    @SysLog("保存申请")
    @RequestMapping("/save")
    @RequiresPermissions("bus:apply:save")
    public R save(BusApplyEntity busApply) {
        busApplyService.save(busApply);

        return R.ok(busApply);
    }

    /**
     * 下载订单
     */
    @SysLog("下载订单")
    @RequestMapping("/down")
    @RequiresPermissions("bus:apply:list")
    public void down(@RequestBody SearchParam<BusApplyVo> params, HttpServletResponse response) {
        List<BusApplyVo> list = busApplyService.queryListVo(params.getEntity());
        busApplyService.downLoad(response, list);
    }

    /**
     * 修改申请
     */
    @SysLog("修改申请")
    @RequestMapping("/update")
    @RequiresPermissions("bus:apply:update")
    public R update(BusApplyEntity busApply) {
        busApplyService.update(busApply);

        return R.ok(busApply);
    }

    /**
     * 删除申请
     */
    @SysLog("删除申请")
    @RequestMapping("/delete")
    @RequiresPermissions("bus:apply:delete")
    public R delete(Long[]ids) {
        busApplyService.deleteBatch(ids);

        return R.ok();
    }

    /**
     * 所有申请
     */
    @SysLog("所有申请")
    @RequestMapping("/queryAll")
    public R queryAll (@RequestParam Map<String,Object> params) {

        List<BusApplyEntity> busApplyList = busApplyService.queryList(params);

        return R.ok(busApplyList);
    }

    /**
     * 所有enums
     */
    @SysLog("所有enums")
    @RequestMapping("/dmz/options")
    public R options() {
        HashMap<String,Object> options = new HashMap();
//        options.put("statusOptions", BusApplyStatusEnum.names());
//        options.put("typeOptions",BusApplyTypeEnum.names());
        options.put("leaveTypeOptions",BusApplyLeaveTypeEnum.names());
        return R.ok(options);
    }

    /**
    @ModelAttribute
    public SearchParam<BusApplyEntity> searchParam(SearchParam<BusApplyEntity> params, BusApplyEntity busApply) {
        if (busApply != null) {
            params.setEntity(busApply);
        }

        return params;
    }
 **/
    /***********自定义开始***********/
}
